<?php
class SuMaSmsHttp {
	private $CorpID = "htxgcwcom106";
	private $Pwd = "htxgcwcom123456";
	private $host = "http://120.132.132.102/WS/";
        private $queryAccount = "";
        
	private $type = 1;
	private $subid = "";
	function __construct($type = 1) { 
            if ($type===1){ // GET URL传参方式
                $this->queryAccount = "?CorpID=".$this->CorpID."&Pwd=".$this->Pwd;
            }else{ // POST 传参方式
                $this->type = $type;
                $this->queryAccount = array (
                    'CorpID' => $this->CorpID,
                    'Pwd' => $this->Pwd
                );
            }
        }
	function _BatchSend2($mobile, $content) {
            $content=mb_convert_encoding($content,'GBK','UTF-8');
            $content=rawurlencode($content);

            $path = "BatchSend2.aspx";
            $params = array (
                'Mobile' => $mobile,
                'Content' => $content
            );
            return self::_getCodeStatus($this->send($path, $params));
	}
	function _GetReportSMS(){
            $path = "GetReportSMS.aspx";
            return $this->send($path);
	}        
        function send( $path, $params=array() ){
            if ($this->type === 1){
                $querystr = "";
                foreach($params as $k => $v){
                    $querystr .= "&".$k."=".$v;
                }
                $gateway = $this->host.$path.$this->queryAccount.$querystr;
                $result = file_get_contents($gateway);
            }else{
                $params = array_merge($this->queryAccount, $params); 
                $client=curl_init();
                curl_setopt($client, CURLOPT_URL, $this->host.$path);
                curl_setopt($client, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($client, CURLOPT_CONNECTTIMEOUT, 5);
                curl_setopt($client, CURLOPT_POST,1);
                curl_setopt($client, CURLOPT_POSTFIELDS, $params);
                $result = curl_exec($client);
                curl_close($client);
            }
            return $result;
        }

	static function _getCodeStatus($status) {
		$arrCode = self::reponseCode ();
                if ($status>0) $status=0;
		return $arrCode [$status];
	}
	private static function reponseCode() {
		return array (
				"0" => "操作成功",
				"-1" => "账号无效",
				"-2" => "参数：无效",
				"-3" => "帐号或密码错误",
				"-5" => "余额不足，请先充值",
				"-6" => "定时发送时间不是有效的时间格式",
				"-8" => "发送内容需在1到300字之间",
				"-9" => "发送号码为空",
				"-10" => "定时时间不能小于系统当前时间",
				"-100" => "限制IP访问",
                                "-101" => "调用接口速度太快"
		);
	}
}
?>